# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#

@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

# TODO: remove after changing [private plugins]
set_and_check(OpenVINO_SOURCE_DIR "@OpenVINO_SOURCE_DIR@") # KMB
set_and_check(OpenVINO_MAIN_SOURCE_DIR "@OpenVINO_SOURCE_DIR@") # KMB

# Variables to export in plugin's projects

set(ie_options "@IE_OPTIONS@")
list(APPEND ie_options CMAKE_CXX_COMPILER_LAUNCHER CMAKE_C_COMPILER_LAUNCHER
                       CMAKE_CXX_LINKER_LAUNCHER CMAKE_C_LINKER_LAUNCHER
                       CMAKE_BUILD_TYPE CMAKE_SKIP_RPATH CMAKE_INSTALL_PREFIX
                       CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET)
file(TO_CMAKE_PATH "${CMAKE_CURRENT_LIST_DIR}" cache_path)

message(STATUS "The following CMake options are exported from Inference Engine Developer package")
message(" ")
foreach(option IN LISTS ie_options)
    if(NOT DEFINED "${option}")
        load_cache("${cache_path}" READ_WITH_PREFIX "" ${option})
    endif()
    message("    ${option}: ${${option}}")
endforeach()
message(" ")

# for samples in 3rd party projects
if(ENABLE_SAMPLES)
    set_and_check(gflags_DIR "@gflags_BINARY_DIR@")
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
    # Disable warning as error for private components
    set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)
endif()

#
# Content
#

find_dependency(IEDevScripts
                PATHS "${OpenVINO_SOURCE_DIR}/cmake/developer_package"
                NO_CMAKE_FIND_ROOT_PATH
                NO_DEFAULT_PATH)

find_dependency(InferenceEngine
                PATHS "${CMAKE_CURRENT_LIST_DIR}"
                NO_CMAKE_FIND_ROOT_PATH
                NO_DEFAULT_PATH)

find_dependency(ngraph
                PATHS "${CMAKE_CURRENT_LIST_DIR}"
                NO_CMAKE_FIND_ROOT_PATH
                NO_DEFAULT_PATH)

if(TARGET openvino::runtime AND NOT TARGET IE::runtime)
    add_library(IE::runtime INTERFACE IMPORTED)
    set_target_properties(IE::runtime PROPERTIES
        INTERFACE_LINK_LIBRARIES openvino::runtime)
endif()

# WA for cmake: it exports ngraph as IE::ngraph in the IE export list
# while we already have ngraph export in its own export list as ngraph::ngraph
if(TARGET ngraph::ngraph AND NOT TARGET IE::ngraph)
    add_library(IE::ngraph INTERFACE IMPORTED)
    set_target_properties(IE::ngraph PROPERTIES INTERFACE_LINK_LIBRARIES ngraph::ngraph)
endif()

_ov_find_tbb()

foreach(component @openvino_export_components@)
    include("${CMAKE_CURRENT_LIST_DIR}/${component}_dev_targets.cmake")
endforeach()

if(TARGET IE::ov_core_dev AND NOT TARGET openvino::core::dev)
    add_library(openvino::core::dev INTERFACE IMPORTED)
    set_target_properties(openvino::core::dev PROPERTIES
        INTERFACE_LINK_LIBRARIES IE::ov_core_dev)
endif()

if(TARGET IE::runtime::dev AND NOT TARGET openvino::runtime::dev)
    add_library(openvino::runtime::dev INTERFACE IMPORTED)
    set_target_properties(openvino::runtime::dev PROPERTIES
        INTERFACE_LINK_LIBRARIES IE::runtime::dev)
endif()

if(ENABLE_SYSTEM_PUGIXML)
    set(_ov_pugixml_pkgconfig_interface "@pugixml_FOUND@")
    set(_ov_pugixml_cmake_interface "@PugiXML_FOUND@")
    if(_ov_pugixml_pkgconfig_interface)
        find_dependency(PkgConfig)
    elseif(_ov_pugixml_cmake_interface)
        find_dependency(PugiXML)
    endif()
    if(PugiXML_FOUND)
        set_property(TARGET pugixml PROPERTY IMPORTED_GLOBAL TRUE)
        add_library(IE::pugixml ALIAS pugixml)
    elseif(PkgConfig_FOUND)
        if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
            set(pkg_config_quiet_arg QUIET)
        endif()
        if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
            set(pkg_config_required_arg REQUIRED)
        endif()

        pkg_search_module(pugixml
                          ${pkg_config_quiet_arg}
                          ${pkg_config_required_arg}
                          IMPORTED_TARGET GLOBAL
                          pugixml)

        unset(pkg_config_quiet_arg)
        unset(pkg_config_required_arg)

        if(pugixml_FOUND)
            add_library(IE::pugixml ALIAS PkgConfig::pugixml)

            # PATCH: on Ubuntu 18.04 pugixml.pc contains incorrect include directories
            get_target_property(interface_include_dir PkgConfig::pugixml INTERFACE_INCLUDE_DIRECTORIES)
            if(interface_include_dir AND NOT EXISTS "${interface_include_dir}")
                set_target_properties(PkgConfig::pugixml PROPERTIES
                    INTERFACE_INCLUDE_DIRECTORIES "")
            endif()
        endif()
    endif()

    # debian 9 case: no cmake, no pkg-config files
    if(NOT TARGET IE::pugixml)
        find_library(PUGIXML_LIBRARY NAMES pugixml DOC "Path to pugixml library")
        if(PUGIXML_LIBRARY)
            add_library(IE::pugixml INTERFACE IMPORTED GLOBAL)
            set_target_properties(IE::pugixml PROPERTIES INTERFACE_LINK_LIBRARIES "${PUGIXML_LIBRARY}")
        else()
            message(FATAL_ERROR "Failed to find system pugixml in OpenVINO Developer Package")
        endif()
    endif()
endif()

# inherit OpenCV from main IE project if enabled
if ("@OpenCV_FOUND@")
    load_cache("${cache_path}" READ_WITH_PREFIX "" OpenCV_DIR)
    find_dependency(OpenCV)
endif()

#
# Extra Compile Flags
#

if(CMAKE_COMPILER_IS_GNUCXX)
    ie_add_compiler_flags(-Wno-error=unused-variable)
    ie_add_compiler_flags(-Wno-error=unused-but-set-variable)
    if(SUGGEST_OVERRIDE_SUPPORTED)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-suggest-override")
    endif()
endif()

# Don't threat deprecated API warnings as errors in 3rd party apps
ie_deprecated_no_errors()
